# 美原油指数
import json
import common.dataBase as db
import requests


def get_data(url):
    headers = {
        'Referer': 'https://www.cngold.org/img_date/conc.html'
    }
    response = requests.get(url, headers=headers)
    json_data = json.loads(response.text[15:])
    quote = json_data[0]['data'][0]['quote']
    return quote['q67'], quote['q63'], quote['q59']


def app():
    url = 'https://api.jijinhao.com/realtime/quotejs.htm?codes=JO_108879&currentPage=1&pageSize=1&_=1649768659302'
    d = get_data(url)
    print(d)
    name = d[0]
    price = d[1]
    price_range = ''
    today = d[2]
    insert_sql = f'INSERT INTO mat_price VALUES (null, "{name}", "{price}","{price_range}", "{today}", "{url}")'
    db.save([insert_sql])


if __name__ == "__main__":
    app()
